import copy
import json

import scrapy

from zhilian.items import ZhilianItem


class ZlSpider(scrapy.Spider):
    name = 'zl'
    allowed_domains = ['capi.zhaopin.com']
    start_urls = ['https://capi.zhaopin.com/capi/searchrecommend/searchPositions?channel=wxxiaochengxu'
                  '&v=1.0&platform=12&d=F0D00D22-9887-4645-8522-F36335B077CB&version=0.0.0&pageIndex=1&pageSize=30'
                  '&order=0&eventScenario=wxmpZhaopinSearchV2'
                  '&S_SOU_FULL_INDEX=%E7%AE%97%E6%B3%95'   #换关键字
                  '&S_SOU_POSITION_TYPE=1%3B2%3B4'
                  '&cvNumber=JH086133206R90500000000'
                  '&at=90a7d5103c984072896bf57be65f9c81'
                  '&rt=c644d6c20996493d940420aedc96ae51'.format(i) for i in range(1, 31)]
    #大数据开发  %E5%A4%A7%E6%95%B0%E6%8D%AE%E5%BC%80%E5%8F%91
    # 爬虫 = %E7%88%AC%E8%99%AB
    # 数据仓库 = %E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93
    # 算法 = %E7%AE%97%E6%B3%95
    # 数据分析 = %E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90
    # 可视化 = %E5%8F%AF%E8%A7%86%E5%8C%96
    # 数据挖掘 = %E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%98

    def parse(self, response):
        item=ZhilianItem()
        html = response.text
        datas=json.loads(html)
        for row in datas['data']['list']:               # json数据里的循环列表
            item['company'] = row['companyName'] # 公司
            item['wages'] = row['salary60']      # 薪水
            item['work_name']=row['name']        # 职位
            item['address'] = row['workCity']     # 公司地址
            item['experience']=row['workingExp']   # 工作经验
            item['education'] = row['education']     # 学历
            print(item)
            yield item
